package com.hy.erp.inventory.service;

import java.util.List ;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

/*import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;
*/
import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.CargoSpaceDao;
import com.hy.erp.inventory.dao.PositionTypeDao;
import com.hy.erp.inventory.dao.interfaces.ICargoSpaceDao;
import com.hy.erp.inventory.dao.interfaces.IMaterielDao;
//import com.hy.erp.inventory.extjs.gxt.ui.client.data.BaseModel;
import com.hy.erp.inventory.pojo.CargoSpace;
import com.hy.erp.inventory.pojo.interfaces.ICargoSpace;
import com.hy.erp.inventory.pojo.interfaces.IMateriel;
import com.hy.erp.inventory.service.interfaces.ICargoSpaceService;
//import com.hy.erp.inventory.vsoft.libra.enterprise.framework.persistence.entity.AbstractPersistentEntity;

/*@ Name ( "cargoSpaceService" )
@ Scope ( ScopeType.STATELESS )
@ Stateless
*/
@Component("cargoSpaceService")
public class CargoSpaceService extends AbstractBusinessService < CargoSpaceDao > implements ICargoSpaceService
{
	
	private ICargoSpaceDao cargoSpaceDao=null;

	@Resource(name="cargoSpaceDao")
	public void setPositionTypeDao(ICargoSpaceDao cargoSpaceDao) {
		this.cargoSpaceDao = cargoSpaceDao;
	}


	@ Override
	public boolean addCargoSpace (
									CargoSpace cargoSpace )
	{


		if ( null == cargoSpace)
		{
			return true ;
		}
		
		else
		{
			System.out
						.println ("ssssssssssssssssssssssffffffffffffffffhghhhhhhhhhhhhhhhhhhhhhh") ;


	//		ICargoSpaceDao cargoSpaceDao =
	//		                       ( ICargoSpaceDao ) this
	//		                                          .getDao ( ICargoSpace.class ) ;
			
			return cargoSpaceDao
			                .persist ( cargoSpace ) ;
		}
		
	
	
	}

	@ Override
	public boolean modifyCargoSpace (
										CargoSpace cargoSpace )
	{


		if ( ( null == cargoSpace )
			     || ( null == cargoSpace
			                                .getIdentifier ( ) )
			     || ( cargoSpace
			                        .getIdentifier ( )
			                        .trim ( )
			                        .length ( ) == 0 ) )
			{
				return true ;
			}
			else
			{
//
	//			ICargoSpaceDao cargoSpaceDao =
        //            ( ICargoSpaceDao ) this
        //                               .getDao ( ICargoSpace.class ) ;
				
		
					
				if ( null == cargoSpace )
				{
					throw new ArchitectureFoundationException  (
					                                            "修改实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
				}
				
				
				return ( cargoSpaceDao
				                  .merge ( cargoSpace ) != null ) ;
			}
		
	
	
	}

	@ Override
	public Integer removeCargoSpace (
										String [ ] cargoSpaceIds )
	{


		if ( ( null == cargoSpaceIds)
			     || ( cargoSpaceIds.length == 0 ) )
			{
				return new Integer (
				                     0 ) ;
			}
			else
			{


		//		ICargoSpaceDao cargoSpaceDao =
       //             ( ICargoSpaceDao ) this
        //                               .getDao ( ICargoSpace.class ) ;
				
		
				return cargoSpaceDao
				                .remove ( cargoSpaceIds ) ;
			}
	
	
	}

	@ Override
	public String [ ] addCargoSpace (
										Object [ ] cargoSpace )
	{

		if ( null == cargoSpace)
		{
			return null ;
		}
		
		else
		{

//			ICargoSpaceDao cargoSpaceDao =
	//		                       ( ICargoSpaceDao ) this
	//		                                          .getDao ( ICargoSpace.class ) ;
			CargoSpace[] cargoSpaces=new CargoSpace[cargoSpace.length];
			for(int i=0;i<cargoSpace.length;i++)
			{
				CargoSpace cargoSpace2=( CargoSpace ) cargoSpace[i];
				cargoSpaces[i]=cargoSpace2;
			}
			return cargoSpaceDao
			                .persist ( cargoSpaces ) ;
		}
		
	
	}

	@ Override
	public List < CargoSpace > getAllCargoSpace ( )
	{
	//	ICargoSpaceDao cargoSpaceDao =
  //          ( ICargoSpaceDao ) this
  //                             .getDao ( ICargoSpace.class ) ;
		

		return cargoSpaceDao
		                .find ( ) ;
	}

	@ Override
	public CargoSpace getCargoSpaceById (
											String id )
	{
		if (  null == id )
		{
			return null ;
		}
		else
		{
	//		ICargoSpaceDao cargoSpaceDao =
	//            ( ICargoSpaceDao ) this
	//                               .getDao ( ICargoSpace.class ) ;
			
                                        
			return cargoSpaceDao.findByIdentifier ( id );
			
		}
	}

	/*@ Override
	public ICargoSpace getCargoSpaceById (
											AbstractPersistentEntity baseModel )
	{

		if (  null ==baseModel )
		{
			return null ;
		}
		else
		{
			String id =baseModel.get ( "identifier" );
		
			
			ICargoSpaceDao cargoSpaceDao =
	            ( ICargoSpaceDao ) this
	                               .getDao ( ICargoSpace.class ) ;
			
                                        
			return cargoSpaceDao.findByIdentifier ( id );
			
		}
	
	}*/

	@ Override
	public String [ ] modifyCargoSpace (
											Object [ ] cargoSpace )
	{


		if ( null == cargoSpace)
		{
			return null ;
		}
		
		else
		{

	//		ICargoSpaceDao cargoSpaceDao =
	//		                       ( ICargoSpaceDao ) this
	//		                                          .getDao ( ICargoSpace.class ) ;
			CargoSpace[] cargoSpaces=new CargoSpace[cargoSpace.length];
			for(int i=0;i<cargoSpace.length;i++)
			{
				CargoSpace cargoSpace2=( CargoSpace ) cargoSpace[i];
				cargoSpaces[i]=cargoSpace2;
			}
			return cargoSpaceDao
			                .merge  ( cargoSpaces ) ;
		}
		
	
	
	}

	

}
